<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <!-- https://vuejs.org/v2/guide/ -->
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  <title>VueApp</title>
</head>

<body>

  <div id="app">
    <div>
      <button v-on:click="counter += 1">Add 1</button>
      <p>You clicked the button {{counter}} times</p>
    </div>

    <div>
      <button v-on:click="greet()">Click</button>
      <p></p>
    </div>

    <div>
      <button class="btn" v-on:click="greet2('ola mundao', $event)">Click</button>
      <p></p>
    </div>

    <div>
      <!-- quando digitar roda a funcao keypess, quando apertar enter roda a keySubmit -->
      <input type="text" v-on:keyup="keypress" v-on:keypress.enter="keySubmit">
    </div>

    <br><br>
    <div>
      <form v-on:submit="formSubmit">
        <input type="text" v-model="msg" placeholder="Entre com alguma coisa">
        <input type="submit" value="Enviar">
      </form>
    </div>

  </div>

  <script>

    let app = new Vue({
      el: '#app',
      data: {
        msg: 'Hello Word',
        counter: 0
      },
      methods: {
        greet: function () {
          alert('Ola tudo bem.')
        },
        greet2: function (greeting, event) {
          // alert(greeting)
          // console.log(event) // retorna muita informacao sobre o campo
          // console.log(event.target.tagName)  // BUTTON
          console.log(event.target.className)  // btn de class="btn"
        },
        keypress(event) {
          console.log('Pressinou a tecla')
          console.log(event.target.value)
        },
        keySubmit(event) {
          console.log('Apertou o Enter')
        },
        formSubmit() {
          // alert('Formulario enviado')

          // v-model para pegar o valor que vai ser enviado
          alert(this.msg)
        }

      }

    })

  </script>

</body>

</html>